<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.sinodata.bsm.common.vo.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>资源暂停规则添加</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/> 
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/crontab.jsp"%>
	<%@ include file="../include/timeUnit.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<style type="text/css">
		.tdValue{
			border: 1px solid #D6D3D6;
			line-height: 26px;
			height: 32px;
			padding-left: 5px;
			overflow: hidden;
		}
	</style>
	<script type="text/javascript">
	
		function cancel(){
			getTopWin(window).closejBox('inputPauseRuleWindow');
		}
		
		function pauseRule(value){
			if(value==1){
				$('#weekDiv').show();
				$('#sectionDiv').hide();
			}else if(value==2){
				$('#weekDiv').hide();
				$('#sectionDiv').show();
				$('#beginTime').val(getCurrentTime());
			}else{
				$('#weekDiv').hide();
				$('#sectionDiv').hide();
			}
		}
		
		function getCurrentTime(){
			 var $currentDate = new Date();
			 var years = $currentDate.getFullYear();
			 var month = add_zero($currentDate.getMonth()+1);
			 var days = add_zero($currentDate.getDate());
			 var hours = add_zero($currentDate.getHours());
			 var minutes = add_zero($currentDate.getMinutes());
			 var ndate = years+"-"+month+"-"+days+" "+hours+":"+minutes;
			 return ndate;
		}
		
		function add_zero(temp)
		{
			 if(temp<10) 
			 		return "0"+temp;
			 else 
			 		return temp;
		}
		
		//保存
		function savePauseRule(){
			var $typeValue = $("input[name='type']:checked").val();
			var ruleValue = '';
			if($typeValue==1){
				var $pauseTime =ctd.results()
				var $continuedTime=stu.results();
				
				if(($pauseTime.split('*').length-1)>=4){
					$.jBox.alert("暂停方式时间不能为空","提示",{width:150});
					return;
				}
				
				if($continuedTime<1){
					$.jBox.alert("持续时间不能为0","提示",{width:150});
					return;
				}else{
					ruleValue = $pauseTime+'@'+$continuedTime;
				}
				
			}else if($typeValue==2){
				var $beginTime = $('#beginTime').val();
				var $endTime   = $('#endTime').val();
				if($endTime<$beginTime&&$endTime!=''){
					$.jBox.alert("结束时间不能小于起始时间","提示",{width:170});
					return;
				}else{
					ruleValue = $beginTime+'@'+$endTime;
				}
			}else{
				    ruleValue = getCurrentTime();
			}
			
			var entity = {
				"type":$typeValue,
				"rule":ruleValue,
				"status":1
			};
			var pauseWindow = getTopWin(window).currentWin['inputPauseRuleWindow'];
			pauseWindow.savePauseRule(entity);
			getTopWin(window).closejBox('inputPauseRuleWindow');
		}
		
	</script>
  </head>
  
  <body style="padding:5px;" >
    <fieldset style="border:1px solid #627eb7 ;padding-left:10px;margin-bottom: 5px;" >
    	<legend >暂停类型</legend>
    	<input type="radio" name="type" checked='checked' value="1" onclick="pauseRule(this.value)" /> 周期
		<input type="radio" name="type" value="2" onclick="pauseRule(this.value)" /> 定期
		<input type="radio" name="type" value="0" onclick="pauseRule(this.value)" /> 完全暂停
    </fieldset>
	<div id="weekDiv" >   
	    <table  class="table_eidt"  >
	    	<tbody>
	    		<tr>
	    			<td class="td_left" style="width:120px;" >暂停方式</td>
	    			<td class="tdValue" >
	    				 <div id='crontabDiv'  ></div>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td class="td_left"  >持续时间</td>
	    			<td class="tdValue" >
		    			<div id='stuDiv' ></div>	
		    		</td>
	    		</tr>
	    	</tbody>
	    </table>
	    <script>
        	var ctd = new Crontabs("crontabDiv");
        	var stu = new SimpleTimeUnit("stuDiv","ddHHmm");
			stu.show();
			stu.reversal('60');
        	ctd.setTU(stu); // 关联两个控件
        	function showCrontab(dom){
        		dom.title = ctd.results();
        		if(!ctd.checkDay()){
        			dom.title += " | " + "持续时间控件的当前值不合法";
        		}
        	}
        	
        </script>
	</div>
	<div id="sectionDiv" style="display:none;">
		<table class="table_eidt" >
			<tbody>
	    		<tr>
	    			<td class="td_left" style="width:120px;" >起始时间</td>
	    			<td class="tdValue" >
	    				<input type="text" name="beginTime" id="beginTime" class="Wdate"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:'%y-%M-%d %H:%m'})"   />
	    			</td>
	    		</tr>
	    		<tr>
	    			<td class="td_left"  >结束时间</td>
	    			<td class="tdValue" >
	    				<input type="text" name="endTime" id="endTime" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})"  />
	    			</td>
	    		</tr>
	    	</tbody>
		</table>
	</div>
	<div class="btn-div" >
   			<input type="button" value="保存" onclick="savePauseRule()" class="btn-4"  /> 
   			<input type="button" value="取消" onclick="cancel()" class="btn-4" />
	</div>
  </body>
</html>
